import { listLeaningCategory } from "@/api/examine/leaningCategory";
export const common =  {
  data(){
    return{
      // 学习类别列表数据
      leaningCategoryList: [],
      props:{
        value:"id",
        label: 'name'
      },
      publishTimeRange: null,
    }
  },
  methods:{
    /**获取类别列表 */
    getCategoryList() {
      listLeaningCategory().then(response => {
        this.leaningCategoryList = this.handleTree(response.data, "id", "parentId");
        console.log(this.leaningCategoryList)
      });
    },
    //选择学习类别
    changeCategory(val){
      if(val && val.length){
        this.form.categoryId = val[val.length-1]
      }
    },
    //获取时间范围查询条件
    getTimeRange(data){
      let arr = []
      let dateObj = {}
      if(data && data.length){
        dateObj.startTime = `${this.formatDate(data[0],'yyyy-MM-dd')} 00:00:00`
        dateObj.endTime= `${this.formatDate(data[1],'yyyy-MM-dd')} 23:59:59`
      }
      console.log(dateObj)
      return dateObj
    },
    formatDate(value,args) {
      var dt = value
      if(args == 'yyyy-M-d') {// yyyy-M-d
        let year = dt.getFullYear();
        let month = dt.getMonth() + 1;
        let date = dt.getDate();
        return `${year}-${month}-${date}`;
      } else if(args == 'yyyy-M-d H:m:s'){// yyyy-M-d H:m:s
        let year = dt.getFullYear();
        let month = dt.getMonth() + 1;
        let date = dt.getDate();
        let hour = dt.getHours();
        let minute = dt.getMinutes();
        let second = dt.getSeconds();
        return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
      } else if(args == 'yyyy-MM-dd') {// yyyy-MM-dd
        let year = dt.getFullYear();
        let month = (dt.getMonth() + 1).toString().padStart(2,'0');
        let date = dt.getDate().toString().padStart(2,'0');
        return `${year}-${month}-${date}`;
      } else {// yyyy-MM-dd HH:mm:ss
        let year = dt.getFullYear();
        let month = (dt.getMonth() + 1).toString().padStart(2,'0');
        let date = dt.getDate().toString().padStart(2,'0');
        let hour = dt.getHours().toString().padStart(2,'0');
        let minute = dt.getMinutes().toString().padStart(2,'0');
        let second = dt.getSeconds().toString().padStart(2,'0');
        return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
      }
    }
  },
  created() {
    this.getCategoryList();
  }
}
